/**********************************************************************************************/
// dgt_BoolElement.h
//
// Common Lib for Digital Studio
// Block of management of bool functions
// Class of elementary part of bool function
//
// Copyright Diamant Group 2008
/**********************************************************************************************/
#ifndef _DGT_BOOLELEMENT_H_
#define _DGT_BOOLELEMENT_H_

#include "dgtKernel.h"
#include "dgt_SmartMacros.h"

SMART_CLASS( dgt_BoolElement );

/**********************************************************************************************/
WX_DECLARE_OBJARRAY( dgt_BoolElement_Ptr, BoolElementArray );

/**********************************************************************************************/
/**
* @brief Function for merging some bool elements with help of overall operation
*		 Only for elements with same operation!!
* @param inArray Input array of bool elements
* @param inLimit Limit of variables ( or inputs ) in uniting elements
* @param isGenInvert If this parameter = true, each union will be followed by invertion
* @return Merged array
*/
BoolElementArray				MergeElements(	BoolElementArray	inArray,
												unsigned			inLimit,
												bool				isGenInvert);

/**********************************************************************************************/
/**
* @param inArray Input array of bool elements
* @return count of elements in first level
*/
unsigned						get_FirstLevelCount( BoolElementArray inArray );


/**********************************************************************************************/
/**
* \class for representation elementary part of bool function
*/
class dgt_BoolElement
{
	public://///////////////////////////////////////////////////////////////////////////////////

		/**
		* @brief Ctor as default
		*/
								dgt_BoolElement();

		/**
		* @brief Dtor as default
		*/
virtual							~dgt_BoolElement()								{};

		/**
		* @brief Function for getting operation of boolean element 
		* @return Carried out operation
		*/
		BOOL_OPERATION			get_Operation( void );

		/**
		* @brief Function for setting operation of boolean element  
		* @param inOp New operation as BOOL_OPERATION
		*/
		void					set_Operation( BOOL_OPERATION inOp );

		/**
		* @brief Function for getting array of variables 
		* @return Array of variables
		*/
		wxArrayInt				get_OpCodes( void );

		/**
		* @brief Function for setting array of variables
		* @param inArray Array of codes of variables
		*/
		void					set_OpCodes( wxArrayInt inArray );

		/**
		* @brief Function for getting array of attributes of inversion of variables, 
		* @return Array of attributes
		*/
		wxBoolArray				get_Inverts( void );

		/**
		* @brief Function for setting array of attributes of inversion of variables, 
		* @param inArray New array of attributes
		*/
		void					set_Inverts( wxBoolArray inArray );

		/**
		* @brief Adds new operand to element
		* @param code Code of new element ( will be added to m_OpCodes )
		* @param isInvert Attribute of inversion
		*/
		void					AddNewOperand( int code, bool isInvert );

		/**
		* @return Count of operands in element
		*/
		unsigned long 			Count( void );

		/**
		* @brief Function for increase input count in boolean element
		* @param inNewInputCount New count of inputs in element
		* @return Element with new input count
		*/
		dgt_BoolElement_Ptr		IncreaseInputs( unsigned long inNewInputCount );

		/**
		* @brief Function for reduce input count in boolean element
		* @param inNewInputCount New count of inputs in element
		* @return Array of elements with new input count
		*/
		BoolElementArray		ReduceInputs( unsigned long inNewInputCount );

	private:////////////////////////////////////////////////////////////////////////////////////

		BOOL_OPERATION			m_Operation;	/*!< Carried out operation */

		/** @brief Array of variables, which are used in operation 
		*
		* If >0 - it is number from array of variables from object dgt_BoolFunction,
		* into which enters this structure ( From 0  - exact number of variable )
		* If <0 - absolute value of it - it is number from array of elementary parts
		* of bool functions from object dgt_BoolFunction, into which enters this structure
		* ( From -1 - it means that -1 - first elementary part )
		*/
		wxArrayInt				m_OpCodes;	

		/** @brief Array of attributes of inversion of variables
		*
		* If true - variable, with same number in m_OpCodes without invertion
		* if false - inversion present
		*/
		wxBoolArray				m_Inverts;
};


#endif //_DGT_BOOLELEMENT_H_